Skip to content

fix(process-daemon): wait on events instead of 25 ms polls on Windows - #65669

Draft
Hona wants to merge 1 commit into
devfrom
daemon-wait-events
Draft

Hona wants to merge 1 commit into
devfrom
daemon-wait-events

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

Issue for this PR

Closes #65668

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Two Windows waits that every terminal keystroke paid for:

  1. Accept loop (transport/windows.rs): Listener::wait now blocks with WaitForMultipleObjects on the pending ConnectNamedPipe's OVERLAPPED event and a real Wake event, up to the caller's timeout. Before, it slept 25 ms (thread::sleep, POLL_INTERVAL is removed).
    • Wake is now a manual-reset event: notify sets it, and drain tests and resets it, as the Unix Wake behaves.
    • An already-connected pending instance returns at once.
    • The loop no longer wakes on its own; it ends on a connection, a wake, or the server's safety-net timeout.
  2. Output batch (service.rs): on Windows the batch takes only what is already queued (a deadline of now) instead of recv_deadline(now + 1 ms). That deadline sleeps a whole 15.6 ms timer tick on Windows. Unix keeps its 1 ms batch.

timed_out stays false on Windows, so the missed-wake detector stays off, as before.

How did you verify your code works?

  • Measured today (the bug): a dev server with opencode-pty 0.6.0, cmd.exe at its prompt, 60 keys 40 ms apart, echo timed on the server's terminal WebSocket. p50 51 ms (p95 160 ms, min 32 ms).
  • Measured with this fix (earlier): the same two changes in the 0.4.0 daemon, on the same machine and server code. Echo p50 5.7 ms (p95 17.5 ms, min 3.5 ms), down from 52 ms. The accept loop's sleeps ended on a connection (p50 2.9 ms) instead of every 25 ms. The code these change is unchanged between 0.4.0 and 0.6.0.
  • New Windows unit tests in transport/windows.rs:
    • drain reports and clears a notify.
    • wait sleeps its whole timeout with nothing to report (it used to return after 25 ms).
    • wait returns at once on a wake and within a second on a connection.
  • rustfmt --check on the changed files. I have not built 0.6.0 with the patch locally; the Windows job of check-process-daemon.yml builds it and runs the tests.

Screenshots / recordings

No picture: latency, measured above.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: terminal echo takes ~50 ms per key (opencode-pty polls every 25 ms)

1 participant